const CONST = require('../../../scripts/configs/const');
cc.Class({
    extends: cc.Component,

    properties: {
        spIcon: cc.Sprite,
        spArrayFly: [cc.SpriteFrame],
    },

    // LIFE-CYCLE CALLBACKS:

    setIcon(icon) {
        this.spIcon.spriteFrame = this.spArrayFly[icon - 1];
    },

    onLoad() {
        this.icon = cc.find('icon', this.node);
        this.icon.on('touchstart', this.onTouchStart.bind(this));
        this.icon.on('touchmove', this.onTouchMove.bind(this));
        this.icon.on('touchend', this.onTouchEnd.bind(this));
    },

    onTouchStart(event) {
        this.startPos = this.node.getPosition();
    },

    onTouchMove(event) {
        if (ICPC.gameDataManager.gameState != CONST.GAME_STATE.GAME) return;
        let sPos = event.getStartLocation();
        let mPos = event.getLocation();
        this.node.x = this.startPos.x + (mPos.x - sPos.x);
        // this.node.y = this.startPos.y + (mPos.y - sPos.y);
    },

    onTouchEnd(event) {

    },

    start() {

    },

    // update (dt) {},
});
